<style >
  table.formTable {
    font-family: verdana, arial, sans-serif;
    font-size: 0.875rem;
    color: #333333;
    border-width: 0px;
    border-color: #dcdfe6;
    border-collapse: collapse;
    width: 100%;
  }

  table.formTable td {
    border-width: 0px;
    padding: 20px;
    border-style: solid;
    border-color: #dcdfe6;
    background-color: #ffffff;
    padding:2px;
    text-align: center;
  }

  table.formTable td:first-child {
    width: 100px;
    text-align: right;
  }

  table.formTable td:last-child {
  	 color: #E6A23C; 
  }
  
      #tableIconForBizStylePoint + .layui-table-view .layui-table-body tbody > tr > td {
        padding: 0;
    }

    #tableIconForBizStylePoint + .layui-table-view .layui-table-body tbody > tr > td > .layui-table-cell {
        height: 60px;
        line-height: 60px;
    }

    .tdImg {
        width: 35px;
        height:35px;
        max-width: none;
        cursor: pointer;
    }

    .layui-table-view {
        margin: 0;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar" id="tbToolBar">
                <div class="layui-form-item">
<!-- 					<div class="layui-inline">
					  <div class="layui-btn-group" style="float: right;">
					   	<button type="button" class="layui-btn " id="btnImportBizPolygonForPOI">
					   		POI入库
					   	</button>
					  </div>
					</div>  -->               
                    <div class="layui-inline" style="float: right;margin-right: 0px;">
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<label class="layui-form-label w-auto">场景</label>
							<div class="layui-input-inline mr0">
						      <select name="sceneId" lay-filter="sceneId">
						        <option value="">--全部--</option>
						        #for(scene : scenes)
						        	 <option value="#(scene.id)">#(scene.title)</option>
						        #end
						      </select>
							</div>
						</div> 
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<label class="layui-form-label w-auto">名称</label>
							<div class="layui-input-inline mr0">
								<input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
							</div>
						</div>
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<button class="layui-btn icon-btn" lay-filter="formSubSearchBizPolygon" lay-submit>
								<i class="layui-icon">&#xe615;</i>查询
							</button>
						</div>					
					</div>
				</div>
				<table class="layui-table" id="tableBizPolygon" lay-filter="tableBizPolygon"></table>
			</div>
		</div>
	</div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarBizPolygon">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="tableStateBizPolygon">
#[[  {{#  if(d.status === '1'){ }}
    <span style="color: #23aa2e;">正常</span>
  {{#  } else { }}
	<span style="color: #ff0000;">禁止</span>
  {{#  } }}
]]#
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="modelSelectSceneScript">
		<form id="modelSelectSceneForm" lay-filter="modelSelectSceneForm" class="layui-form model-form">
	        <div class="layui-form-item">
	            <label class="layui-form-label">场景</label>
	            <div class="layui-input-block">
			      <select name="sceneId" lay-filter="sceneId">
			        <option value=""></option>
			        #for(scene : scenes)
			        	 <option value="#(scene.id)">#(scene.title)</option>
			        #end
			      </select>
	            </div>
	        </div>
	        <div class="layui-form-item text-right">
				<button class="layui-btn" id="btnSelectFile">选择文件</button>
	        </div>
		</form>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin','upload','config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var upload = layui.upload;
        var admin = layui.admin;
        var config = layui.config;

        form.render('select');
        // 渲染表格
        var insTb = table.render({
            elem: '#tableBizPolygon',
            url: '#(ctx)/biz/marker/polygon/listData', 
            page: true,
            toolbar: false,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号'},
                {field: 'name', sort: false, title: '名称'},
                {field: 'code', sort: false, title: '标识'},
                {
                    field: 'createTime', sort: false, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '创建时间'
                },
                {align: 'left', toolbar: '#tableBarBizPolygon', title: '操作', fixed: 'right',width: 170}
            ]],
        });
        
        // 搜索
        form.on('submit(formSubSearchBizPolygon)', function (data) {
            insTb.reload({where: data.field}, 'data');
        });
        
        // 添加
		$('#btnImportBizPolygonForPOI').click(function () {
			showImportPOIModel();
		});
        



        // 工具条点击事件
        table.on('tool(tableBizPolygon)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
            	showEditModel(data);
            } else if (layEvent === 'del') { 
                doDel(data.id, data.name);
            }
        });
        
        // 显示编辑弹窗
        function showImportPOIModel(data) {
        	 admin.open({
                type: 1,
                title: 'POI资源',
                content: $('#modelSelectSceneScript').html(),
                shade: 0.3,
                offset: 't'	,
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    form.render();
                    
                    upload.render({
                        elem: '#btnSelectFile'
                        ,url: '#(ctx)/biz/kml/poi'
                        ,accept: 'file'
                        ,exts: 'kml'
                       	,data: {
                       		sceneId:'#(sceneId)'
                       	}
                     	,before: function(obj){ 
                            var formData=form.val('modelSelectSceneForm');  // 回显数据
                            if(formData){
                            	console.log(formData);
                            }
                            console.log(formData);
                  	    	return false;
                  	    }
                  	    ,done: function(res, index, upload){
                  		layer.closeAll('loading');
                          if (200==res.code) {
                              layer.msg(res.message, {icon: 1});
                          } else {
                              layer.msg(res.message, {icon: 2});
                          }
                  	    }
                  	    ,error: function(index, upload){
                  	     layer.closeAll('loading');
                  	     layer.msg("上传失败！", {icon: 2});
                  	   }       
                   });
                    
                    
                }
            });
        }
        

        // 删除
        function doDel(id, name) {
        	layer.confirm('确定要克隆“【<span style="color:red;">' + name + '</span>】”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/marker/polygon/delete', {
                    id: id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.message, {icon: 1});
                        insTb.reload({}, 'data');
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                }, 'get');
            });
        }

    });
</script>
